﻿using System.Diagnostics;

namespace TroubleshootingofBeanBagAssistant.lCheck
{
	public class AllowAppstoAccessYourMicrophoneCheck : IDiagnosticCheck
	{
		public string Name => "检查并修复允许应用访问你的麦克风";

		public CheckResult Run()
		{
			if (!SystemMicrophone.IsAppMicrophoneAccessAllowed())
			{
				SystemMicrophone.EnableAppMicrophoneAccess();
				// 打开设置页面让用户确认
				Process.Start(new ProcessStartInfo
				{
					FileName = "ms-settings:privacy-microphone",
					UseShellExecute = true,
				});
				return new CheckResult
				{
					Title = "检测到麦克风访问未开启，已自动开启",
					Detail = ""
				};
			}
			else
			{
				// 依然建议弹出设置页面让用户确认
				Process.Start(new ProcessStartInfo
				{
					FileName = "ms-settings:privacy-microphone",
					UseShellExecute = true,
				});
				return new CheckResult
				{
					Title = "已开启系统设置允许应用访问你的麦克风",
					Detail = "已开启"
				};
			}
		}
	}
}
